package org.micropayment.model;

import java.io.Serializable;
import java.util.Date;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 *
 * @author jj
 */
@Entity
@Table(name = "Token")
@NamedQueries({
    @NamedQuery(name = "Token.findAll", query = "SELECT t FROM Token t"),
    @NamedQuery(name = "Token.findById", query = "SELECT t FROM Token t WHERE t.id = :id"),
    @NamedQuery(name = "Token.findByCallbackUrl", query = "SELECT t FROM Token t WHERE t.callbackUrl = :callbackUrl"),
    @NamedQuery(name = "Token.findBySecret", query = "SELECT t FROM Token t WHERE t.secret = :secret"),
    @NamedQuery(name = "Token.findByAccessConfirmationDate", query = "SELECT t FROM Token t WHERE t.accessConfirmationDate = :accessConfirmationDate"),
    @NamedQuery(name = "Token.findByVerifier", query = "SELECT t FROM Token t WHERE t.verifier = :verifier"),
    @NamedQuery(name = "Token.findByIsAccessToken", query = "SELECT t FROM Token t WHERE t.isAccessToken = :isAccessToken"),
    @NamedQuery(name = "Token.findByRemoved", query = "SELECT t FROM Token t WHERE t.removed = :removed")})
public class Token implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @Column(name = "tokenValue", nullable = false)
    private String tokenValue;
    @Column(name = "callbackUrl")
    private String callbackUrl;
    @Column(name = "requestTokenValue")
    private String requestTokenValue;
    @Basic(optional = false)
    @Column(name = "secret")
    private String secret;
    @Column(name = "requestAuthorizationDate")
    @Temporal(TemporalType.TIMESTAMP)
    private Date requestAuthorizationDate;
    @Column(name = "requestUnauthorizedDate")
    @Temporal(TemporalType.TIMESTAMP)
    private Date requestUnauthorizedDate;
    @Column(name = "accessConfirmationDate")
    @Temporal(TemporalType.TIMESTAMP)
    private Date accessConfirmationDate;
    @Column(name = "verifier")
    private String verifier;
    @Basic(optional = false)
    @Column(name = "isAccessToken")
    private Boolean isAccessToken;
    @Basic(optional = false)
    @Column(name = "removed")
    private Boolean removed = Boolean.FALSE;
    @JoinColumn(name = "micropaymentUserId", referencedColumnName = "id")
    @ManyToOne
    private MicropaymentUser micropaymentUserId;
    @JoinColumn(name = "micropaymentConsumerId", referencedColumnName = "id")
    @ManyToOne(optional = false)
    private MicropaymentConsumer micropaymentConsumerId;

    public Token() {
    }

    public Token(String tokenValue) {
        this.tokenValue = tokenValue;
    }

    public Token(String tokenValue, String value, String secret, Date requestUnauthorizedDate, String verifier, Boolean isAccessToken, Boolean removed) {
        this.tokenValue = tokenValue;
        this.secret = secret;
        this.requestUnauthorizedDate = requestUnauthorizedDate;
        this.verifier = verifier;
        this.isAccessToken = isAccessToken;
        this.removed = removed;
    }

    public String getTokenValue() {
        return tokenValue;
    }

    public void setTokenValue(String tokenValue) {
        this.tokenValue = tokenValue;
    }

    public String getCallbackUrl() {
        return callbackUrl;
    }

    public void setCallbackUrl(String callbackUrl) {
        this.callbackUrl = callbackUrl;
    }

    public String getSecret() {
        return secret;
    }

    public void setSecret(String secret) {
        this.secret = secret;
    }

    public String getVerifier() {
        return verifier;
    }

    public void setVerifier(String verifier) {
        this.verifier = verifier;
    }

    public Boolean getIsAccessToken() {
        return isAccessToken;
    }

    public void setIsAccessToken(Boolean isAccessToken) {
        this.isAccessToken = isAccessToken;
    }

    public Serializable getRemoved() {
        return removed;
    }

    public void setRemoved(Boolean removed) {
        this.removed = removed;
    }

    public MicropaymentUser getMicropaymentUserId() {
        return micropaymentUserId;
    }

    public void setMicropaymentUserId(MicropaymentUser micropaymentUserId) {
        this.micropaymentUserId = micropaymentUserId;
    }

    public MicropaymentConsumer getMicropaymentConsumerId() {
        return micropaymentConsumerId;
    }

    public void setMicropaymentConsumerId(MicropaymentConsumer micropaymentConsumerId) {
        this.micropaymentConsumerId = micropaymentConsumerId;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (tokenValue != null ? tokenValue.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Token)) {
            return false;
        }
        Token other = (Token) object;
        if ((this.tokenValue == null && other.tokenValue != null) || (this.tokenValue != null && !this.tokenValue.equals(other.tokenValue))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "org.micropayment.model.Token[tokenValue=" + tokenValue + "]";
    }

    /**
     * @return the requestAuthorizationDate
     */
    public Date getRequestAuthorizationDate() {
        return requestAuthorizationDate;
    }

    /**
     * @param requestAuthorizationDate the requestAuthorizationDate to set
     */
    public void setRequestAuthorizationDate(Date requestAuthorizationDate) {
        this.requestAuthorizationDate = requestAuthorizationDate;
    }

    /**
     * @return the requestUnauthorizedDate
     */
    public Date getRequestUnauthorizedDate() {
        return requestUnauthorizedDate;
    }

    /**
     * @param requestUnauthorizedDate the requestUnauthorizedDate to set
     */
    public void setRequestUnauthorizedDate(Date requestUnauthorizedDate) {
        this.requestUnauthorizedDate = requestUnauthorizedDate;
    }

    /**
     * @return the accessConfirmationDate
     */
    public Date getAccessConfirmationDate() {
        return accessConfirmationDate;
    }

    /**
     * @param accessConfirmationDate the accessConfirmationDate to set
     */
    public void setAccessConfirmationDate(Date accessConfirmationDate) {
        this.accessConfirmationDate = accessConfirmationDate;
    }

    /**
     * @return the requestTokenValue
     */
    public String getRequestTokenValue() {
        return requestTokenValue;
    }

    /**
     * @param requestTokenValue the requestTokenValue to set
     */
    public void setRequestTokenValue(String requestTokenValue) {
        this.requestTokenValue = requestTokenValue;
    }

}
